cmake_minimum_required(VERSION 3.12)
project(MyCoordinateProject VERSION 1.0 LANGUAGES C CXX)  # 同时支持 C 和 C++

# 设置C标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 设置构建目录在当前项目内
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})  # 可执行文件直接输出到build/
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})  # 静态库输出到build/
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})  # 动态库输出到build/

# 编译器警告和静态分析
if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()


# 根据构建类型设置编译选项
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug)
endif()

message(STATUS "构建类型: ${CMAKE_BUILD_TYPE}")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-g -O0)
    message(STATUS "调试符号已启用")
else()
    add_compile_options(-O2 -DNDEBUG)
    message(STATUS "优化已启用")
endif()

# 创建库
add_library(math_lib
    src/eigen.c
)

add_library(coordinate_transformer
    src/coordinate_transformer.c
)


# 设置库的头文件包含路径
target_include_directories(math_lib PUBLIC
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}
)

target_include_directories(coordinate_transformer PUBLIC
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}
)

# 链接数学库到库
target_link_libraries(math_lib PRIVATE m)
target_link_libraries(coordinate_transformer PRIVATE math_lib m)

# 创建可执行文件
add_executable(my_coordinate_app
    examples/main.c
)

# 链接库到可执行文件
target_link_libraries(my_coordinate_app
    coordinate_transformer
    m  # 如果可执行文件也需要数学库
)

# 设置可执行文件的头文件包含路径
target_include_directories(my_coordinate_app PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}
)